package com.koicarp.university.graduate.web.controller.schoolInfoManage;

import com.koicarp.university.graduate.auth.annotation.OperLog;
import com.koicarp.university.graduate.auth.constant.ModuleNameEnum;
import com.koicarp.university.graduate.auth.constant.OperateLogTypeEnum;
import com.koicarp.university.graduate.service.entity.schoolInfoManage.ClassManage;
import com.koicarp.university.graduate.service.service.schoolInfoManage.IClassManageService;
import com.koicarp.university.graduate.service.vo.schoolInfoManage.ClassManageVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 【学校基本信息：班级管理表】(ClassManage)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:49:30
 */
@Slf4j
@RestController
@RequestMapping("classManage")
@RequiredArgsConstructor
@Api(tags = "(班级管理)表控制层")
public class ClassManageController {
    /**
     * 服务对象
     */
    private final IClassManageService classManageService;

    @RequestMapping("getAllClassManageInfo")
    @ApiOperation(value = "查询所有班级信息",notes = "可带班级条件查询")
    public UniversityResponse getAllClassManageInfo(@RequestBody ClassManage classManage){
        UniversityResponse response=null;
        try{
            response = classManageService.getAllClassManage(classManage);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("getClassManageInfoWithPage")
    @ApiOperation(value = "班级信息查询-普通查询，分页" ,notes = "班级信息查询-普通查询，分页")
    public UniversityResponse getClassManageInfoWithPage(ClassManageVo vo){
        UniversityResponse response=null;
        try{
            if (vo.getSort().equals("+id")){
                vo.setSort("asc");
            }else{
                vo.setSort("desc");
            }
            response = classManageService.getClassManageInfoWithPage(vo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("saveClassManageInfo")
    @ApiOperation(value = "班级信息增加(单个)" ,notes = "班级信息增加(单个)")
    @OperLog(moduleName = ModuleNameEnum.SchoolClass,type = OperateLogTypeEnum.CREATE,operDesc = "班级信息增加（单个）")
    public UniversityResponse saveClassManageInfo(@RequestBody ClassManage classManage){
        UniversityResponse response=null;
        try{
            response = classManageService.insert(classManage);
        }catch (Exception e){
            log.error("增加失败!!!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeClassManageInfo")
    @ApiOperation(value = "删除班级信息(单个)" ,notes = "删除班级信息（单个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolClass,type = OperateLogTypeEnum.DELETE,operDesc = "删除班级信息（单个）")
    public UniversityResponse removeClassManageInfo(@RequestBody ClassManage classManage){
        UniversityResponse response=null;
        try{
            response = classManageService.deleteById(classManage.getId());
        }catch (Exception e){
            log.error("删除失败！!!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeListInfo")
    @ApiOperation(value = "删除班级信息(多个)" ,notes = "删除班级信息（多个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolClass,type = OperateLogTypeEnum.DELETE,operDesc = "删除班级信息（多个）")
    public UniversityResponse removeListInfo(@RequestBody List<Integer> idList){
        UniversityResponse response=null;
        try{
            response = classManageService.deleteListById(idList);
        }catch (Exception e){
            log.error("删除失败!!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("modifyClassManageInfo")
    @OperLog(moduleName = ModuleNameEnum.SchoolClass,type = OperateLogTypeEnum.UPDATE,operDesc = "修改班级信息")
    @ApiOperation(value = "修改班级信息" ,notes = "修改班级信息")
    public UniversityResponse modifyClassManageInfo(@RequestBody ClassManage classManage){
        UniversityResponse response=null;
        try{
            response = classManageService.update(classManage);
        }catch (Exception e){
            log.error("修改失败!!!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
}